# -*- coding: utf-8 -*-
# created on 2016/5/5

from mathsolver.functions.base import *
from sympy import sqrt


# 求直线与圆相交的弦长
class LengthOFYuan(BaseFunction):
    """
    直线x-\\sqrt{3}y+2=0被圆x^{2}+y^{2}=4截得的弦长为()
    """
    def solver(self, *args):
        juli = args[0].sympify()
        banjing = args[1].sympify()
        xianchang = 2 * sqrt(banjing ** 2 - juli ** 2)
        self.steps.append(["", "由垂径定理，知弦长为 %s" % (new_latex(xianchang))])
        self.output.append(BaseNumber(xianchang))
        self.label.add("求直线与圆相交的弦长")
        return self


# 直线y=kx+3与圆(x-1)^{2}+(y+2)^{2}=4相交于M,N两点
class LengthOFYuan002(BaseFunction):
    def solver(self, *args):
        xiancheng = args[0].sympify()
        pointnames = args[1].sympify()
        self.output.append(BaseSymbolValue({sympify('distance(%s,%s)' % (pointnames[0], pointnames[1])): xiancheng}))
        return self


# 若|MN|≥2\\sqrt{3}
class LengthOFYuan003(BaseFunction):
    def solver(self, *args):
        f1, op, f2 = args[0].sympify()
        self.output.append(base_gen([f1, op, f2]))
        self.steps.append(["", "∴ %s" % (base_gen([f1, op, f2]).printing())])
        self.label.add("根据弦长的范围求参")
        return self


# 返回|AB|的直线
class ReturnDistance(BaseFunction):
    def solver(self, *args):
        xianchang_points = args[0].sympify()
        distance = sympify('distance(%s,%s)' % (xianchang_points[0], xianchang_points[1]))
        value = self.search(distance)
        for v in value:
            self.steps.append(["", "∴%s = %s" % (BaseDistance([xianchang_points[0], xianchang_points[1]]).printing(),
                                                 BaseValue(v).printing())])
        return self


# 若直线:x-y+2=0与圆C:(x-3)^{2}+(y-3)^{2}=4相交于A,B两点,则\\overrightarrow{CA}•\\overrightarrow{CB}的值为()
class YuanCenterVector(BaseFunction):
    def solver(self, *args):
        return self


if __name__ == '__main__':
    pass
